<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class MemberRealname extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("MemberRealname");
	}
	public function add(){
		$this->postData['userid'] = $this->uinfo['id'];
        $message = $this->validate($this->postData, 'MemberRealname.add');
        if ($message!== true) {
            return $this->app_error($message);
        } 
        $realname = $this->postData['realname'];
        $result = $this->modelDb->where('userid', $this->uinfo['id'])->find();
        if ($result) {
            $id = $this->modelDb->update_data($this->postData);
            if($id === false){
             return $this->app_error($this->modelDb->getError());
            } else{
            return $this->app_success(['id'=>$id]);
            }
            
        } else {
            $id = $this->modelDb->save_data($this->postData);
            if($id === false){
               return $this->app_error($this->modelDb->getError());
            } else{
    	       return $this->app_success(['id'=>$id]);
            }
        }
       
    }
    public function update(){
        $id = $this->modelDb->update_data($this->postData);
        if($id === false){
        	return $this->app_error($this->modelDb->getError());
        }
        else{
            $info = $this->modelDb->get_data(['item_id'=>$id]);
        }
    	return $this->app_success($info);
    }
}